home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / book.exe / LANSHOW.C < prev    next >
C/C++ Source or Header  |  1991-09-22  |  5KB  |  181 lines

  1. /*
  2. // LANSHOW.C    A LANtastic NET SHOW clone
  3. //
  4. // (c) Copyright 1990, 1991 Adrian King.
  5. //
  6. //
  7. //        This code was developed for inclusion in the book
  8. //        "Running LANtastic", by Adrian King, published by
  9. //        Bantam Books, October 1991.
  10. //
  11. // $Header:   F:/LANBOOK/SRC/LAN/VCS/LANSHOW.C_V   1.0   13 Jul 1991 11:28:14  $
  12. //
  13. // $Log:   F:/LANBOOK/SRC/LAN/VCS/LANSHOW.C_V  $
  14. //
  15. //   Rev 1.0   13 Jul 1991 11:28:14
  16. //Initial revision.
  17. //
  18. //    This program is a single module example showing how to use both 
  19. //    the LANtastic API and the C library presented in "Running LANtastic".
  20. //
  21. //    The program is a 'clone' of the NET SHOW function of the LANtastic 
  22. //    NET utility. No attention has been paid to efficiency details.
  23. //
  24. //    Although error messages are displayed, very little error processing 
  25. //    is done.
  26. //
  27. //    Build notes:
  28. //
  29. //        This module must be linked with the NOS library (NOSLIB.LIB). 
  30. //    
  31. //        Make sure that nos.h and noslib.h are on the INCLUDE path for the
  32. //        compiler.
  33. //
  34. //        Borland Turbo C:    tcc lanshow.c noslib.c
  35. //
  36. //        Borland C++:        bcc lanshow.c noslib.c
  37. //
  38. //        Microsoft C:        cl lanshow.c noslib.c
  39. //
  40. */
  41.  
  42.     // Standard DOS includes
  43.  
  44. #include "stdio.h"
  45. #include "conio.h"
  46. #include "process.h"
  47. #include "dos.h"
  48. #include "string.h"
  49. #include "ctype.h"
  50.  
  51.     // NOS specific includes
  52.  
  53. #include "nos.h"
  54. #include "noslib.h"
  55.  
  56.     // Macros
  57.  
  58. #define    ERROR    NOSperror("LANSHOW")    // Print a NOS error message
  59.  
  60. #define TICKS    18                        // Per second. Ought to be 18.2...
  61.  
  62. #ifdef __TURBOC__
  63. unsigned _heaplen = 1000;                // Smaller heap for Turbo C
  64. #endif
  65.  
  66.     //
  67.     // MAIN
  68.     //
  69.     // Display (in order):
  70.     //
  71.     //        A title
  72.     //        Details of this machine
  73.     //      The status of record and file locking
  74.     //        The status of the message service
  75.     //        The LPT timeout
  76.     //        The logins and redirections current on this node
  77.     //        Other servers available on the network
  78.     //
  79.     // There are no parameters to this program, you run it as LANSHOW
  80.     //    
  81.  
  82. void main()
  83. {
  84.     char cpName[D_NAMESZ+2];
  85.     int nVersion;
  86.     int    nLoaded;
  87.     int nAdapter;
  88.     BOOL bName;
  89.     char *cp;    
  90.     int nMsgflag;
  91.     int nTimeout;
  92.     int    i, j;
  93.     char cpUsername[D_NAMESZ];
  94.     char cpDevice[D_NAMESZ];
  95.     char cpPath[128];
  96.     WORD wType;
  97.  
  98.     nLoaded = NOSPresence();            // See what's loaded                    // Check LANBIOS and REDIR present
  99.     if (nLoaded == -1){
  100.                                         // NOSPresence() doesn't set an error
  101.                                         // This error message is not a clone
  102.         printf("LANSHOW: Network not loaded\n");
  103.         exit(1);
  104.     }
  105.         
  106.                                         // Use NOS version number in title
  107.     nVersion = NOSGetVersion();
  108.     printf("LANSHOW version %d.%02d - (C) Copyright 1991 Adrian King\n",
  109.                 nVersion >> 8,
  110.                 nVersion & 0xff);
  111.  
  112.                                         // Get the node name
  113.  
  114.     if (NOSGetMachineName(&cpName[2], &nAdapter, &bName) == -1)
  115.         ERROR;
  116.  
  117.     cpName[0] = cpName[1] = '\\';        // Add the \\prefix and
  118.                                         // null terminate the name
  119.     cp = strchr(cpName, ' ');
  120.     if (cp != NULL)
  121.         *cp = '\0';            
  122.                                         // Report node details
  123.     printf("Machine %s is being used as a %s%s\n",
  124.                 &cpName[2],
  125.                 (nLoaded & 0x08)?"Redirector":"",
  126.                 (nLoaded & 0x40)?" and a Server":"");
  127.     
  128.                                         // Report on locking status
  129.     nLoaded = NOSSharePresence();
  130.     printf("File and record locking is currently %s\n",
  131.                             (nLoaded == -1)?"ENABLED":"DISABLED");
  132.  
  133.                                         // Report on message service
  134.     if (NOSGetMsgFlag(&nMsgflag) == -1)
  135.         ERROR;
  136.  
  137.     printf("Unsolicited messages will %s and %s\n",
  138.                 (nMsgflag & MPB_beep)?"BEEP":"NOT BEEP",
  139.                 (nMsgflag & MPB_auto_pop_up)?"POP-UP":"NOT POP-UP");
  140.  
  141.                                         // Report on LPT timeout
  142.     if (NOSGetLPTTimeout(&nTimeout) == -1)
  143.         ERROR;
  144.  
  145.     printf("LPT timeout in seconds: %d\n", nTimeout / TICKS);
  146.  
  147.                                         // Report on logins
  148.     i = 0;
  149.     while (NOSGetLogin(&i, &cpName[2], &nAdapter) != -1){
  150.         
  151.         cp = strchr(cpName, ' ');        // Null terminate the server name
  152.         if (cp != NULL)
  153.             *cp = '\0';
  154.                                         // Get login name
  155.         if (NOSGetUserName(&i, cpUsername, &nAdapter) != -1)
  156.             printf("Logged into %s as %s on adapter %d\n",
  157.                         cpName, cpUsername, nAdapter);
  158.  
  159.         i++;                             // Increment server index 
  160.     };
  161.                                         // Report on redirections
  162.     j = 0; 
  163.     while (NOSGetRedirDevice(j, cpDevice, cpPath, &wType) != -1){
  164.         printf("%s %s is redirected to %s\n",
  165.                     ((wType & 0xFF) == 3)?"Printer":"Disk",
  166.                     cpDevice,
  167.                     cpPath);
  168.         j++;                            // Increment device index
  169.     }
  170.  
  171.                                         // Report on other available servers
  172.     i = 0;
  173.     while (NOSGetServer(&i, &cpName[2], &nAdapter) != -1){
  174.         printf("Server %s is available on adapter %d\n", cpName, nAdapter);
  175.         i++;
  176.     };
  177.  
  178.     exit(0);                            // Normal exit
  179. }
  180.  
  181.